<template>
  <common-search :col-layout="{xxl: 6, xl:8, lg: 8, md: 12, sm: 24, xs: 24}" v-model="query" :formItems="formItems" @search="search" @reset="reset"></common-search>
  <a-button type="primary" @click="exports" :loading="exportLoading" v-modulePerm="['fba:export']">
    <template #icon>
      <ExportOutlined />
    </template>
    导出
  </a-button>
  <common-table
      :columns="columns"
      :dataSource="dataList"
      v-model:localPagination="page"
      @paginationChange="onPageChange"
      v-model:loading="loading"
      :scroll="{ x: 'max-content'}"
  >

  </common-table>
</template>
<script>
export default {
  name:'inventoryPools-fba'
}
</script>
<script setup>
import { ref,onMounted } from "vue";
import CommonTable from "@/components/commonTable/index.vue";
import CommonSearch from "@/components/commonSearch/index.vue";
import {useSearchTable} from "@/hooks/table/useSearchTable";
import {getManyDictItems} from "@/api/system/dict.js";
import {message} from "ant-design-vue";
import {postFile} from "@utils/service/index.js";
import {getFBAPage} from "@/api/inventoryPools/fba.js";
const columns = [
  {
    "dictCode": "site",
    "dataIndex": "site",
    "title": "站点",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "productSku",
    "title": "平台SKU",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "amzSku",
    "title": "亚马逊销售SKU",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "fnsku",
    "title": "亚马逊FNSKU",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "asin",
    "title": "亚马逊ASIN",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "afnFulfillableQty",
    "title": "可售库存",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "afnUnsellableQty",
    "title": "不可售库存",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "afnReservedQty",
    "title": "保留库存",
    "align": "center",
    "fieldType": "Long"
  },
  {

    "dataIndex": "afnOnwayQty",
    "title": "在途库存",
    "align": "center",
    "fieldType": "Long"
  },
  {

    "dataIndex": "afnInboundingQty",
    "title": "上架中库存",
    "align": "center",
    "fieldType": "Long"
  },
  {

    "dictCode": "pdmProductType",
    "dataIndex": "updateDate",
    "title": "易仓ERP同步AMZ时间",
    "align": "center",
    "fieldType": "String"
  },
]
const formItems = ref([
  {
    label:'平台SKU',
    type:'input',
    field:'productSku',
    options:[]
  },
  {
    label:"亚马逊FNSKU",
    type:'input',
    field: 'fnsku',
  },
  {
    label:'亚马逊ASIN',
    type:'input',
    field:'asin',
  },
  {
    label:'亚马逊销售SKU',
    type:'input',
    field:'amzSku',
  },
  {
    label:"站点",
    type:'select',
    field: 'site',
    options:[]
  },
])
const selectedRowKeys = ref([])
const exportLoading = ref(false)
const { dataList, query, loading, page, search, reset, onPageChange } = useSearchTable({
  searchAPI: getFBAPage,
  queryFactory: () => ({
  }),
  beforeSearch: () => {
  },
});
/**
 * 初始化字典数据
 * @returns {Promise<void>}
 */
const init = async () => {
  try{
    const res = await getManyDictItems({
      dictCodeList:"site"
    })
    formItems.value[4].options = res.result.site
  }catch (e){
    console.log(e)
  }
}
/**
 *  选择行变化事件
 * @param e {Array} 选择行的keys
 */
const onSelectChange = (e) => {
  selectedRowKeys.value = e
}
const exports = async () => {
  try{
    exportLoading.value = true
    const res = await postFile('/fba/export','post',query.value,'FBA库存.xlsx')
    message.success('导出成功')
  }catch (e) {
    message.error(e)
  }finally {
    exportLoading.value = false
  }
}
onMounted(()=>{
  init()
})
</script>
<style scoped>

</style>
